//
//  TTComeOverViewController.swift
//  WeiBo
//
//  Created by 涂永江 on 2017/6/7.
//  Copyright © 2017年 涂永江. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class TTComeOverViewController: UIViewController {

   
    private lazy var uiimage = UIImageView(image: UIImage(named: "ad_background"))

    private lazy var nameUimage:UIImageView = {
       let nameImage = TTHMUserAccountViewModel.sharedAccountModel.accountModel?.avatar_large
        let image = UIImageView(image: UIImage(named: "avatar_default_big"))
        image.layer.cornerRadius = 45
        image.layer.masksToBounds = true
        
        if let imagea = nameImage{
    
            image.sd_setImage(with: URL(string:imagea), placeholderImage: UIImage(named:"avatar_default_big"))
        }else
        {
        image.image = UIImage(named: "avatar_default_big")
        
        }
        
       
        return image
    }()
    
    private lazy var nameLabel:UILabel = {
    
        let label = UILabel()
        let nameLabel = TTHMUserAccountViewModel.sharedAccountModel.accountModel?.name
        
        if let name = nameLabel{
        label.text = "欢迎进入微博世界\(name)"
        }else
        {
         label.text = "哈哈"
        }
            label.font = UIFont.systemFont(ofSize: 16)
        label.alpha = 0
         return label
    }()
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        stratanimation()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
          setUI()
        
            }

    override func loadView() {
        view = uiimage
    }
  
    
    private func setUI()
    {
    
    view.addSubview(nameUimage)
    view.addSubview(nameLabel)
        
        nameUimage.snp.makeConstraints { (make) in
            make.top.equalTo(self.view).offset(200)
            make.centerX.equalTo(self.view)
            make.size.equalTo(CGSize(width: 90, height: 90))
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.nameUimage.snp.bottom).offset(10)
            make.centerX.equalTo(self.nameUimage)
        }
       
    }
    
    private func stratanimation()
    {
    
    nameUimage.snp.updateConstraints { (make) in
        make.top.equalTo(self.view).offset(100)
        }
        
        UIView.animate(withDuration: 2, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 5, options: [], animations: {
            self.view.layoutIfNeeded()
        }) { (_) in
            
            UIView.animate(withDuration: 1, animations: { 
                self.nameLabel.alpha = 1
            }, completion: { (_) in
                //切换首页控制器
                NotificationCenter.default.post(name: NSNotification.Name(rawValue: SwitchRootVCNotificationName), object: self)
            })
        }
    
    }
}
